/**
* 版权所有：福建邮科电信业务部厦门研发中心 
*====================================================
* 文件名称: WebContextInterceptor.java
* 修订记录：
* No    日期				作者(操作:具体内容)
* 1.    Jun 18, 2012			詹保山(softzbs@126.com)(创建:创建文件)
*====================================================
* 类描述：(说明未实现或其它不应生成javadoc的内容)
* 
*/
package com.devframe.web.struts2.interceports;

import org.apache.struts2.ServletActionContext;

import com.devframe.web.MyAction;
import com.devframe.web.MyContext;
import com.devframe.web.Struts2BaseAction;
import com.devframe.web.WebContext;
import com.devframe.web.interceptors.MyInterceptorStack;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;

/**
 *<pre><b><font color="blue">WebContextInterceptor</font></b></pre>
 *
 *<pre><b>&nbsp;--描述说明--</b></pre>
 * <pre>注入web 请求的上下文信息</pre>
 * <pre>
 * <b>--样例--</b>
 *   WebContextInterceptor obj = new WebContextInterceptor();
 *   obj.method();
 * </pre>
 */
public class MyContextInterceptor extends AbstractInterceptor {
	private static final Logger LOG = LoggerFactory.getLogger(MyContextInterceptor.class);
	public String intercept(ActionInvocation invocation) throws Exception {
		Object action=invocation.getAction();
		if(action instanceof Struts2BaseAction){
		    if (LOG.isDebugEnabled()) {
		        LOG.debug("设置webContext");
		    }
			MyContext myContext=new WebContext(ServletActionContext.getRequest());
			((Struts2BaseAction)action).setContext(myContext);
////////////////////////////////////////////////////////			
			Struts2BaseAction baseAction=(Struts2BaseAction)action;
			MyInterceptorStack interceptorStack=baseAction.getInterceptorStack();
		   if(interceptorStack!=null){
			   interceptorStack.before(baseAction.getContext(),(MyAction) action);
		   }
		}
		return invocation.invoke();
	}
}
